from mysql_conn.mysql_conn import MysqlConn
from pg_conn.pg_conn import PgConn
import pandas as pd


def pg2mysql(tables_list=None):
    """
    pg 转入 mysql
    :param tables_list: 需要转入
    :return:
    """
    pg1 = PgConn("127.0.0.1", "postgres", "Pass2word", "blog", '5432')
    mysql1 = MysqlConn("127.0.0.1", 'root', 'Pass2word', 'testdb')
    pg_tables = tables_list or [t[0] for t in pg1.get_tables()]
    for table_name in pg_tables:
        df_data = pg1.get_table_data(table_name)
        mysql1.xls_to_mysql(df_data, table_name)

def oracle2mysql(table_list=None):
    """
    oracle 转入mysql
    :param table_list:
    :return:
    """
    pg1 = PgConn("127.0.0.1", "postgres", "Pass2word", "blog", '5432')
    mysql1 = MysqlConn("127.0.0.1", 'root', 'Pass2word', 'testdb')
    oracle_tables = table_list or []



def csv2mysql(file_path, table_name):
    """
    csv文件导入mysql
    :param file_path: 文件路径
    :param table_name: 导入表名
    :return:
    """
    mysql1 = MysqlConn("127.0.0.1", 'root', 'Pass2word', 'testdb')
    df_data = pd.read_csv(file_path)
    mysql1.xls_to_mysql(df_data, table_name)


if __name__ == '__main__':
    # pg2mysql()
    csv2mysql('pg_authors.csv', 'author_test')
